<template>
	<div class="llf_content">
		<a-form ref="formRef" :model="addFormData" :label-col="{ style: { width: '500px' } }"
			:rules="rules">
			<div class="flex_b">
				<a-form-item name="systemName">
					<template v-slot:label><span :title="systemNotes['system_name']">系统名称</span></template>
					<!-- :disabled="!(systemUpdate['system_name'] && LoginPowerslist['sys_e'])" v-if="showlist['system_name']" -->
					<MyInput :modelV="addFormData.systemName" @submit="addFormData.systemName = $event" maxlength="20" @blur="onsubmit('systemName')"
						v-if="showlist['systemName']"
					/>
					<p @dblclick="Bdclick('systemName')" v-else
						:class="(systemUpdate['systemName'] && LoginPowerslist['sys_e'])?'yes':'no'"
					>{{addFormData.systemName || '无'}}</p>
				</a-form-item>
			</div>
      <div class="flex_b">
        <a-form-item  name="unitName">
          <template v-slot:label><span :title="systemNotes['unitName']">单位名称</span></template>
          <MyInput :modelV="addFormData.unitName" @submit="addFormData.unitName = $event" maxlength="20" @blur="onsubmit('unitName')"
                   v-if="showlist['unitName']"
          />
          <p @dblclick="Bdclick('unitName', (systemUpdate['unitName'] && LoginPowerslist['sys_e']))" v-else
             :class="(systemUpdate['unitName'] && LoginPowerslist['sys_e'])?'yes':'no'"
          >{{addFormData.unitName || '无'}}</p>
        </a-form-item>
      </div>

<!--			<div class="flex_b">-->
<!--				<a-form-item name="app_name">-->
<!--					<template v-slot:label><span :title="systemNotes['app_name']">产品名</span></template>-->
<!--					<MyInput :modelV="addFormData.app_name" @submit="addFormData.app_name = $event" maxlength="20" @blur="onsubmit('app_name')"-->
<!--						v-if="showlist['app_name']"-->
<!--					/>-->
<!--					<p @dblclick="Bdclick('app_name', (systemUpdate['app_name'] && LoginPowerslist['sys_e']))" v-else-->
<!--						:class="(systemUpdate['app_name'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--					>{{addFormData.app_name || '无'}}</p>-->
<!--				</a-form-item>-->
<!--				<a-form-item name="app_protocol">-->
<!--					<template v-slot:label><span :title="systemNotes['app_protocol']">协议</span></template>-->
<!--					<a-select v-model:value="addFormData.app_protocol" placeholder="请选择" v-if="showlist['app_protocol']"-->
<!--						:options="$OPTIONS.PROTOCOL" @blur="onsubmit('app_protocol')"-->
<!--					/>-->
<!--					<p @dblclick="Bdclick('app_protocol', (systemUpdate['app_protocol'] && LoginPowerslist['sys_e']))" v-else-->
<!--						:class="(systemUpdate['app_protocol'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--					>{{addFormData.app_protocol || '无'}}</p>-->
<!--				</a-form-item>-->
<!--			</div>-->
			<div class="flex_b" style="margin-bottom:0">
				<div style="width:100%">
					<a-form-item name="copyright">
						<template v-slot:label><span :title="systemNotes['copyright']">版权归属</span></template>
            <MyInput :modelV="addFormData.copyright" @submit="addFormData.copyright = $event" maxlength="20" @blur="onsubmit('copyright')"
                     v-if="showlist['copyright']"
            />
						<p @dblclick="Bdclick('copyright', (systemUpdate['copyright'] && LoginPowerslist['sys_e']))" v-else
							:class="(systemUpdate['copyright'] && LoginPowerslist['sys_e'])?'yes':'no'"
						>{{addFormData.copyright || '无'}}</p>
					</a-form-item>

				</div>
			</div>
      <div class="flex_b">
        <div style="width:100%">
          <a-form-item name="logo">
            <template v-slot:label><span :title="systemNotes['logo']">LOGO</span></template>
            <UploadImage @success="onImageSuccess" class="new_article my_logo" :imgSrc="addFormData.logo" >
              <template v-slot:updateText>
                <img src="@/assets/image/other/chat_picture.png" alt="">
                <p>上传logo</p>
              </template>
            </UploadImage>
          </a-form-item>
        </div>
      </div>
      <div class="flex_b">
        <a-form-item name="adminDefaultPassword">
          <template v-slot:label><span :title="systemNotes['adminDefaultPassword']">管理员注册默认密码</span></template>
          <a-input-password v-model:value="addFormData.adminDefaultPassword" @blur="onsubmit('adminDefaultPassword')"
                            v-if="showlist['adminDefaultPassword']"
          />
          <p @dblclick="Bdclick('adminDefaultPassword', (systemUpdate['adminDefaultPassword'] && LoginPowerslist['sys_e']))" v-else
             :class="(systemUpdate['adminDefaultPassword'] && LoginPowerslist['sys_e'])?'yes':'no'"
          >******</p>
        </a-form-item>
      </div>
      <div class="flex_b">
<!--        <a-form-item name="userNumberPwdSet">-->
<!--          <template v-slot:label><span :title="systemNotes['userNumberPwdSet']">患者默认密码生成规则</span></template>-->
<!--          <a-select v-model:value="addFormData.userNumberPwdSet" placeholder="请选择" @blur="onsubmit('userNumberPwdSet')"-->
<!--                    v-if="showlist['userNumberPwdSet']"-->
<!--                    :options="$OPTIONS.PASSWORDSET_OPTION" />-->
<!--          <p @dblclick="Bdclick('userNumberPwdSet', (systemUpdate['userNumberPwdSet'] && LoginPowerslist['sys_e']))" v-else-->
<!--             :class="(systemUpdate['userNumberPwdSet'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--          >{{ $OPTIONS.PASSWORDSET[Number(addFormData.userNumberPwdSet)]}}</p>-->
<!--        </a-form-item>-->
      </div>
			<div class="flex_b">

				<a-form-item name="adminDefaultPassword">
					<template v-slot:label><span :title="systemNotes['adminDefaultPassword']">患者注册默认密码</span></template>
					<a-input-password v-model:value="addFormData.adminDefaultPassword" @blur="onsubmit('adminDefaultPassword')"
						v-if="showlist['adminDefaultPassword']"
					/>
					<p @dblclick="Bdclick('adminDefaultPassword', (systemUpdate['adminDefaultPassword'] && LoginPowerslist['sys_e']))" v-else
						:class="(systemUpdate['adminDefaultPassword'] && LoginPowerslist['sys_e'])?'yes':'no'"
					>******</p>
				</a-form-item>
			</div>
<!--			<div class="flex_b">-->
<!--				<a-form-item name="safety_verification">-->
<!--					<template v-slot:label><span :title="systemNotes['safety_verification']">是否开启安全验证</span></template>-->
<!--					<a-select v-model:value="addFormData.safety_verification" placeholder="请选择" @blur="onsubmit('safety_verification')"-->
<!--						v-if="showlist['safety_verification']"-->
<!--						:options="$OPTIONS.SYSTEMSTATUS_OPTION" />-->
<!--					<p  @dblclick="Bdclick('safety_verification', (systemUpdate['safety_verification'] && LoginPowerslist['sys_e']))" v-else-->
<!--						:class="(systemUpdate['safety_verification'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--					>{{$OPTIONS.SYSTEMSTATUS[Number(addFormData.safety_verification)]}}</p>-->
<!--				</a-form-item>-->
<!--			</div>-->
<!--			<div class="flex_b">-->
<!--				<a-form-item name="safety_verification_time">-->
<!--					<template v-slot:label><span :title="systemNotes['safety_verification_time']">限制登录时长</span></template>-->
<!--					<MyInput :modelV="addFormData.safety_verification_time" @submit="addFormData.safety_verification_time = $event" type="number" @blur="onsubmit('safety_verification_time')"-->
<!--						 v-if="showlist['safety_verification_time']"-->
<!--					/>-->
<!--					<p @dblclick="Bdclick('safety_verification_time', (systemUpdate['safety_verification_time'] && LoginPowerslist['sys_e']))" v-else-->
<!--						:class="(systemUpdate['safety_verification_time'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--					>{{addFormData.safety_verification_time || '无'}}</p>-->
<!--				</a-form-item>-->
<!--				<a-form-item name="safety_verification_count">-->
<!--					<template v-slot:label><span :title="systemNotes['safety_verification_count']">限制登录次数</span></template>-->
<!--					<MyInput :modelV="addFormData.safety_verification_count" @submit="addFormData.safety_verification_count = $event"  type="number" @blur="onsubmit('safety_verification_count')"-->
<!--						 v-if="showlist['safety_verification_count']"-->
<!--					/>-->
<!--					<p @dblclick="Bdclick('safety_verification_count', (systemUpdate['safety_verification_count'] && LoginPowerslist['sys_e']))" v-else-->
<!--						:class="(systemUpdate['safety_verification_count'] && LoginPowerslist['sys_e'])?'yes':'no'"-->
<!--					>{{addFormData.safety_verification_count || '无'}}</p>-->
<!--				</a-form-item>-->
<!--			</div>-->
		</a-form>
	</div>
</template>

<script setup lang="ts">
import {ref, computed, watch, nextTick, onMounted} from 'vue';
	import { useSystem  } from '@/store';
	import Message from "@/utils/message";
  import {getSystemInfo} from "@/api/system";

	const System = useSystem();
	// const permission = usePermission();

	System.getSystem();

	const systemInfo = computed(()=> System.$state.systemInfo);
	// const systemNotes = computed(()=> System.$state.systemNotes);
	// const systemUpdate = computed(()=> System.$state.systemUpdate);
	// const LoginPowerslist = computed(()=> permission.$state.LoginPowerslist);
	const systemUpdate = ref({});
	const systemNotes = ref({});
	const addFormData = ref<any>({});
	const rules = {};
	const formRef = ref();
	const createVisible = ref(false);
	const showlist = ref({});

  onMounted(async ()=>{
    await query();
  })
	const Bdclick = (key, bol)=>{
		// if(!bol) return Message.warning('暂无权限修改');
		showlist.value = {};
		showlist.value[key]  = true;
		nextTick(()=>{
			$('input').focus();
		});
	};

  const query:any = async ()=>{
    let res = await getSystemInfo();
    addFormData.value = res[0]
  }

	const onImageSuccess = (data,type)=>{ // 图片上传成功
		const { id, url } = data[0];
		// System.updateSystem({ key:'logo',value:url });
	};

	const onsubmit = (key)=>{
		// console.log(key,"keykeykey")
		showlist.value = {};
    let requestData = {
      id: addFormData.value.id,
    };
    requestData[key] =addFormData.value[key];

    System.updateSystem(requestData);
	};

	// const onClose = ()=>{
	// 	const res = System.closeSystem();
	// 	addFormData.value = JSON.parse(JSON.stringify(res));
	// };

	// const onSuccess = (data)=>{
	// 	const { id } = addFormData.value;
	// 	System.updateSystem({ id, auto_blueprint:data });
	// 	createVisible.value = false;
	// };

	watch(()=>systemInfo.value,()=>{
		// addFormData.value = JSON.parse(JSON.stringify(systemInfo.value));
		// console.log(systemNotes.value,"systemNotessystemNotes")
	},{ immediate:true, deep:true });

</script>

<style lang="less" scoped>
	.llf_content{
		background-color: @white;
		border-radius: 7px;
		align-items: center;
		justify-content: center;
	}
	.ant-form{
		.ant-form-item{
			margin-bottom: 20px;
		}
	}

	.flex_b{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 5px;
		>div{
			width:40%;
		}
	}
	.foot_btns{
		button{
			width:20%
		}
	}
	.no{
		color:#767676;
	}
	// /deep/ .my_logo{
	// 	.img{
	// 		width: 100px !important;
	// 		height: auto !important;
	// 	}
	// }
	// /deep/ .my_article{
	// 	.img{
	// 		width: 200px !important;
	// 		height: auto !important;
	// 	}
	// }

</style>
